package com.beyond.generate;

import com.beyond.generate.service.SysGeneratorService;
import com.beyond.generate.service.impl.SysGeneratorServiceImpl;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * @author zhangyan
 * @version $ Id: GeneratorMain.java, v 0.1 2020/4/24 14:03 zhangyan Exp $
 */
public class GeneratorBuilder {

    public GeneratorBuilder() {
    }

    public void build() throws Exception {
        //读取配置文件
        Configuration configuration = new PropertiesConfiguration("generator.properties");
        //获取表
        String[] tables = configuration.getStringArray("db.tables");
        if (Objects.isNull(tables) || tables.length <= 0) {
            throw new RuntimeException("指定表生成[assignTableGenerate = true]，但是tables配置为空");
        }
        SysGeneratorService service = new SysGeneratorServiceImpl();
        //生成
        service.generatorCode(tables);
    }

    /**
     * 主方法测试
     *
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        //读取配置文件
        Configuration configuration = new PropertiesConfiguration("generator.properties");
        //获取表
        String[] tables = configuration.getStringArray("db.tables");
        SysGeneratorService service = new SysGeneratorServiceImpl();
        //生成
        service.generatorCode(tables);
    }


}
